package com.yoyo.web.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.yoyo.biz.UserBiz;
import com.yoyo.entity.User;

@Controller
public class UserAction {
	
	@Resource
	private UserBiz userbiz;
	private List<User> users;
	private User user;
	private String json;
	
	public UserBiz getUserbiz() {
		return userbiz;
	}
	public void setUserbiz(UserBiz userbiz) {
		this.userbiz = userbiz;
	}
	public List<User> getUsers() {
		return users;
	}
	public void setUsers(List<User> users) {
		this.users = users;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String getJson() {
		return json;
	}
	public void setJson(String json) {
		this.json = json;
	}
	
	public String reg(){
		userbiz.save(this.user);
		return "reged";
	}
	
	public String login(){
		users = userbiz.findAll("username =? and password=?",new Object[]{user.getUsername(),user.getPassword()});
		if(users.size()!=0&&users!=null){
			Map<String,Object> seesion = (Map<String,Object>)ActionContext.getContext().getSession();
			seesion.put("user", user);
			return "logined";
		}else{
			return "success";
		}
	}

}
